#ifndef GX_META_LEXER_H
#define GX_META_LEXER_H

#include "Regex/Regex.h"

namespace GxMetaParser
{
	using namespace GxRegex;

	class LexToken
	{
	public:
		String Str;
		int TypeID;
		int Position;
	};

	typedef Link<LexToken> LexStream;
	
	class LexerError
	{
	public:
		String Text;
		int Position;
	};

	struct LexProfileToken
	{
		String str;
		enum LexProfileTokenType
		{
			Identifier,
			Equal,
			Regex
		} type;
	};

	typedef Link<LexProfileToken> LexProfileTokenStream;
	typedef Link<LexProfileToken>::LinkNode LexProfileTokenNode;

	class MetaLexer : public Object
	{
	private:
		RefPtr<DFA_Table> dfa;
		Array<String> Regex;
		Array<String> TokenNames;
		Array<bool> Ignore;
		String ReadProfileToken(LexProfileTokenNode*n, LexProfileToken::LexProfileTokenType type);
		bool ParseLexProfile(String lex);
		void ConstructDFA();
	public:
		int TokensParsed;
		Array<LexerError> Errors;
		MetaLexer(String LexProfile);
		MetaLexer();
		DFA_Table * GetDFA();
		String GetTokenName(int id);
		int GetRuleCount();
		void SetLexProfile(String lex);
		bool Parse(String str, LexStream & stream);
	};
};

#endif